/*
 *此javaCode由YMS-JDBC替换工具生成，原mapper位置com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductMapper
 */
package com.yonyou.ucf.mdf.app.isvdxq.other.mapper.impl;

import com.yonyou.iuap.yms.api.IYmsJdbcApi;
import com.yonyou.iuap.yms.param.*;
import com.yonyou.iuap.yms.param.ResultSetProcessor;
import com.yonyou.iuap.yms.processor.*;
import com.yonyou.iuap.yms.replace.CollectionUtil;
import com.yonyou.ucf.mdf.app.isvdxq.other.entity.ProductEntity;
import java.sql.Types;
import java.util.*;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Repository;

@Repository
public class ProductMapperImpl  {
    
    @Autowired
    private IYmsJdbcApi ymsJdbcApi;
    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductMapper.selectAll
    
    public List<ProductEntity> selectAll(String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_product where `ytenant_id` = ?;\n";
        parameter.addParam(tenantId);

        ResultSetProcessor processor = new AutoBeanListProcessor(new ProductEntity());
        return (List<ProductEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductMapper.selectByCode
    
    public ProductEntity selectByCode(String code, String tenantId) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_product where `id`=? and `ytenant_id` = ?;\n";
        parameter.addParam(code);
		parameter.addParam(tenantId);

        ResultSetProcessor processor = new AutoBeanProcessor(new ProductEntity());
        return (ProductEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductMapper.selectByIds
    
    public List<ProductEntity> selectByIds(String tenantId, List<String> ids) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" select * from dxqyy_product where `ytenant_id` = ? ");
		parameter.addParam(tenantId);
		if (CollectionUtil.isNotEmpty(ids)) {
			sqlBuilder.append(" and id in ( ");
			String separator0 = " , ";
			for (int index = 0; index < ids.size(); index++) {
				String item = ids.get(index);
				sqlBuilder.append(" ? ");
				parameter.addParam(item);
				if (index < ids.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
			sqlBuilder.append(" ) ");
		}

        
        String sql = sqlBuilder.toString();
        ResultSetProcessor processor = new AutoBeanListProcessor(new ProductEntity());
        return (List<ProductEntity>) ymsJdbcApi.queryForList(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductMapper.updateByPrimaryKey
    
    public int updateByPrimaryKey(ProductEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "update dxqyy_product set `code` = ?, `productName` = ?, `unit` = ?, `unitUseType` = ?, `stockUnit` = ?, `defaultSKUId` = ?, `orgId` = ?, `orgId_Name` = ?, `productApplyRangeId` = ?, `productApplyRange_OrgId` = ?, `productClass` = ?, `productClass_Code` = ?, `manageClass` = ?, `manageClass_Code` = ?, `eventNotify_status` = ?, `isEnabled` = ?, `isStop` = ?, `isAuthorizationManager` = ?, `isCreator` = ?, `isRegistrationManager` = ?, `hasSpecs` = ?, `realProductAttribute` = ?, `realProductAttributeType` = ?, `modifier` = ?, `modifierId` = ?, `modifyTime` = ?, `pubts` = ?, `barCode` = ?, `productTemplate` = ?, `enableAssistUnit` = ?, `isSerialNoManage` = ?, `isBarcodeManage` = ?, `allowNegativeInventory` = ?, `isBatchManage` = ?, `isExpiryDateManage` = ?, `daysBeforeValidityReject` = ?, `validityWarningDays` = ?, `isExpiryDateCalculationMethod` = ?, `expireDateUnit` = ?, `expireDateNo` = ?, `isRefresh_dxq` = ?, `remark_dxq` = ? where `id` = ?\n";
        parameter.addParamWithType(record.getCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductName(), Types.VARCHAR);
		parameter.addParamWithType(record.getUnit(), Types.VARCHAR);
		parameter.addParamWithType(record.getUnitUseType(), Types.INTEGER);
		parameter.addParamWithType(record.getStockUnit(), Types.VARCHAR);
		parameter.addParamWithType(record.getDefaultSKUId(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrgId(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrgId_Name(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductApplyRangeId(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductApplyRange_OrgId(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductClass(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductClass_Code(), Types.VARCHAR);
		parameter.addParamWithType(record.getManageClass(), Types.VARCHAR);
		parameter.addParamWithType(record.getManageClass_Code(), Types.VARCHAR);
		parameter.addParamWithType(record.getEventNotify_status(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsEnabled(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsStop(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsAuthorizationManager(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsCreator(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsRegistrationManager(), Types.VARCHAR);
		parameter.addParamWithType(record.getHasSpecs(), Types.VARCHAR);
		parameter.addParamWithType(record.getRealProductAttribute(), Types.INTEGER);
		parameter.addParamWithType(record.getRealProductAttributeType(), Types.INTEGER);
		parameter.addParamWithType(record.getModifier(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifierId(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifyTime(), Types.VARCHAR);
		parameter.addParamWithType(record.getPubts(), Types.VARCHAR);
		parameter.addParamWithType(record.getBarCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductTemplate(), Types.VARCHAR);
		parameter.addParamWithType(record.getEnableAssistUnit(), Types.BIT);
		parameter.addParamWithType(record.getIsSerialNoManage(), Types.BIT);
		parameter.addParamWithType(record.getIsBarcodeManage(), Types.BIT);
		parameter.addParamWithType(record.getAllowNegativeInventory(), Types.BIT);
		parameter.addParamWithType(record.getIsBatchManage(), Types.BIT);
		parameter.addParamWithType(record.getIsExpiryDateManage(), Types.BIT);
		parameter.addParamWithType(record.getDaysBeforeValidityReject(), Types.INTEGER);
		parameter.addParamWithType(record.getValidityWarningDays(), Types.INTEGER);
		parameter.addParamWithType(record.getIsExpiryDateCalculationMethod(), Types.INTEGER);
		parameter.addParamWithType(record.getExpireDateUnit(), Types.VARCHAR);
		parameter.addParamWithType(record.getExpireDateNo(), Types.INTEGER);
		parameter.addParamWithType(record.getIsRefresh_dxq(), Types.INTEGER);
		parameter.addParamWithType(record.getRemark_dxq(), Types.LONGVARCHAR);
		parameter.addParamWithType(record.getId(), Types.BIGINT);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductMapper.selectCount
    
    public int selectCount(long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select count(1) from dxqyy_product where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new ColumnProcessor(int.class);
        return (int) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductMapper.insertBatch
    
    public int insertBatch(List<ProductEntity> insertBatch) {
        SQLParameter parameter = new SQLParameter(true);
        StringBuilder sqlBuilder = new StringBuilder();
		sqlBuilder.append(" insert into dxqyy_product (`id`, `code`, `productName`, `unit`, `unitUseType`, `stockUnit`, `defaultSKUId`, `orgId`, `orgId_Name`, `productApplyRangeId`, `productApplyRange_OrgId`, `productClass`, `productClass_Code`, `manageClass`, `manageClass_Code`, `eventNotify_status`, `isEnabled`, `isStop`, `isAuthorizationManager`, `isCreator`, `isRegistrationManager`, `hasSpecs`, `realProductAttribute`, `realProductAttributeType`, `modifier`, `modifierId`, `modifyTime`, `pubts`, `ytenant_id`, `barCode`, `productTemplate`, `enableAssistUnit`,`isSerialNoManage`,`isBarcodeManage`, `allowNegativeInventory`,`isBatchManage`,`isExpiryDateManage`, `daysBeforeValidityReject`,`validityWarningDays`, `isExpiryDateCalculationMethod`,`expireDateUnit`, `expireDateNo`,`remark_dxq`,`isRefresh_dxq`) values ");
		if (CollectionUtil.isNotEmpty(insertBatch)) {
			String separator0 = " , ";
			for (int i = 0; i < insertBatch.size(); i++) {
				ProductEntity item = insertBatch.get(i);
				sqlBuilder.append(" (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) ");
				parameter.addParamWithType(item.getId(), Types.BIGINT);
				parameter.addParamWithType(item.getCode(), Types.VARCHAR);
				parameter.addParamWithType(item.getProductName(), Types.VARCHAR);
				parameter.addParamWithType(item.getUnit(), Types.VARCHAR);
				parameter.addParamWithType(item.getUnitUseType(), Types.INTEGER);
				parameter.addParamWithType(item.getStockUnit(), Types.VARCHAR);
				parameter.addParamWithType(item.getDefaultSKUId(), Types.VARCHAR);
				parameter.addParamWithType(item.getOrgId(), Types.VARCHAR);
				parameter.addParamWithType(item.getOrgId_Name(), Types.VARCHAR);
				parameter.addParamWithType(item.getProductApplyRangeId(), Types.VARCHAR);
				parameter.addParamWithType(item.getProductApplyRange_OrgId(), Types.VARCHAR);
				parameter.addParamWithType(item.getProductClass(), Types.VARCHAR);
				parameter.addParamWithType(item.getProductClass_Code(), Types.VARCHAR);
				parameter.addParamWithType(item.getManageClass(), Types.VARCHAR);
				parameter.addParamWithType(item.getManageClass_Code(), Types.VARCHAR);
				parameter.addParamWithType(item.getEventNotify_status(), Types.VARCHAR);
				parameter.addParamWithType(item.getIsEnabled(), Types.VARCHAR);
				parameter.addParamWithType(item.getIsStop(), Types.VARCHAR);
				parameter.addParamWithType(item.getIsAuthorizationManager(), Types.VARCHAR);
				parameter.addParamWithType(item.getIsCreator(), Types.VARCHAR);
				parameter.addParamWithType(item.getIsRegistrationManager(), Types.VARCHAR);
				parameter.addParamWithType(item.getHasSpecs(), Types.VARCHAR);
				parameter.addParamWithType(item.getRealProductAttribute(), Types.INTEGER);
				parameter.addParamWithType(item.getRealProductAttributeType(), Types.INTEGER);
				parameter.addParamWithType(item.getModifier(), Types.VARCHAR);
				parameter.addParamWithType(item.getModifierId(), Types.VARCHAR);
				parameter.addParamWithType(item.getModifyTime(), Types.VARCHAR);
				parameter.addParamWithType(item.getPubts(), Types.VARCHAR);
				parameter.addParamWithType(item.getTenantId(), Types.VARCHAR);
				parameter.addParamWithType(item.getBarCode(), Types.VARCHAR);
				parameter.addParamWithType(item.getProductTemplate(), Types.VARCHAR);
				parameter.addParamWithType(item.getEnableAssistUnit(), Types.BIT);
				parameter.addParamWithType(item.getIsSerialNoManage(), Types.BIT);
				parameter.addParamWithType(item.getIsBarcodeManage(), Types.BIT);
				parameter.addParamWithType(item.getAllowNegativeInventory(), Types.BIT);
				parameter.addParamWithType(item.getIsBatchManage(), Types.BIT);
				parameter.addParamWithType(item.getIsExpiryDateManage(), Types.BIT);
				parameter.addParamWithType(item.getDaysBeforeValidityReject(), Types.INTEGER);
				parameter.addParamWithType(item.getValidityWarningDays(), Types.INTEGER);
				parameter.addParamWithType(item.getIsExpiryDateCalculationMethod(), Types.INTEGER);
				parameter.addParamWithType(item.getExpireDateUnit(), Types.VARCHAR);
				parameter.addParamWithType(item.getExpireDateNo(), Types.INTEGER);
				parameter.addParamWithType(item.getRemark_dxq(), Types.LONGVARCHAR);
				parameter.addParamWithType(item.getIsRefresh_dxq(), Types.INTEGER);
				if (i < insertBatch.size() - 1) {
					sqlBuilder.append(separator0);
				}
			}
		}
		sqlBuilder.append(" ON DUPLICATE KEY UPDATE code=VALUES(code), `productName` = VALUES(productName), `unit` = VALUES(unit), `unitUseType` = VALUES(unitUseType), `stockUnit` = VALUES(stockUnit), `defaultSKUId` = VALUES(defaultSKUId), `orgId` = VALUES(orgId), `orgId_Name` = VALUES(orgId_Name), `productApplyRangeId` = VALUES(productApplyRangeId), `productApplyRange_OrgId` = VALUES(productApplyRange_OrgId), `productClass` = VALUES(productClass), `productClass_Code` = VALUES(productClass_Code), `manageClass` = VALUES(manageClass), `manageClass_Code` = VALUES(manageClass_Code), `eventNotify_status` = VALUES(eventNotify_status), `isEnabled` = VALUES(isEnabled), `isStop` = VALUES(isStop), `isAuthorizationManager` = VALUES(isAuthorizationManager), `isCreator` = VALUES(isCreator), `isRegistrationManager` = VALUES(isRegistrationManager), `hasSpecs` = VALUES(hasSpecs), `realProductAttribute` = VALUES(realProductAttribute), `realProductAttributeType` = VALUES(realProductAttributeType), `modifier` = VALUES(modifier), `modifierId` = VALUES(modifierId), `modifyTime` = VALUES(modifyTime), `pubts` = VALUES(pubts), `barCode` = VALUES(barCode), `productTemplate` = VALUES(productTemplate), `enableAssistUnit` = VALUES(enableAssistUnit), `isSerialNoManage` = VALUES(isSerialNoManage), `isBarcodeManage` = VALUES(isBarcodeManage), `allowNegativeInventory` = VALUES(allowNegativeInventory), `isBatchManage` = VALUES(isBatchManage), `isExpiryDateManage` = VALUES(isExpiryDateManage), `daysBeforeValidityReject` = VALUES(daysBeforeValidityReject), `validityWarningDays` = VALUES(validityWarningDays), `isExpiryDateCalculationMethod` = VALUES(isExpiryDateCalculationMethod), `expireDateUnit` = VALUES(expireDateUnit), `expireDateNo` = VALUES(expireDateNo), `isRefresh_dxq` = VALUES(isRefresh_dxq), `remark_dxq` = VALUES(remark_dxq) ");

        
        String sql = sqlBuilder.toString();
        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductMapper.insert
    
    public int insert(ProductEntity record) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "insert into dxqyy_product (`id`, `code`,  `productName`, `unit`, `unitUseType`,  `stockUnit`, `defaultSKUId`,  `orgId`, `orgId_Name`,  `productApplyRangeId`, `productApplyRange_OrgId`,  `productClass`, `productClass_Code`,  `manageClass`, `manageClass_Code`,  `eventNotify_status`, `isEnabled`,  `isStop`, `isAuthorizationManager`,  `isCreator`, `isRegistrationManager`,  `hasSpecs`, `realProductAttribute`,  `realProductAttributeType`, `modifier`,  `modifierId`, `modifyTime`,  `pubts`, `ytenant_id`, `barCode`, `productTemplate`, `enableAssistUnit`,`isSerialNoManage`,`isBarcodeManage`, `allowNegativeInventory`,`isBatchManage`,`isExpiryDateManage`, `daysBeforeValidityReject`,`validityWarningDays`, `isExpiryDateCalculationMethod`,`expireDateUnit`, `expireDateNo`,`remark_dxq`,`isRefresh_dxq`) values (?, ?,  ?, ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?,  ?, ?, ?,  ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)\n";
        parameter.addParamWithType(record.getId(), Types.BIGINT);
		parameter.addParamWithType(record.getCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductName(), Types.VARCHAR);
		parameter.addParamWithType(record.getUnit(), Types.VARCHAR);
		parameter.addParamWithType(record.getUnitUseType(), Types.INTEGER);
		parameter.addParamWithType(record.getStockUnit(), Types.VARCHAR);
		parameter.addParamWithType(record.getDefaultSKUId(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrgId(), Types.VARCHAR);
		parameter.addParamWithType(record.getOrgId_Name(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductApplyRangeId(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductApplyRange_OrgId(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductClass(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductClass_Code(), Types.VARCHAR);
		parameter.addParamWithType(record.getManageClass(), Types.VARCHAR);
		parameter.addParamWithType(record.getManageClass_Code(), Types.VARCHAR);
		parameter.addParamWithType(record.getEventNotify_status(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsEnabled(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsStop(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsAuthorizationManager(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsCreator(), Types.VARCHAR);
		parameter.addParamWithType(record.getIsRegistrationManager(), Types.VARCHAR);
		parameter.addParamWithType(record.getHasSpecs(), Types.VARCHAR);
		parameter.addParamWithType(record.getRealProductAttribute(), Types.INTEGER);
		parameter.addParamWithType(record.getRealProductAttributeType(), Types.INTEGER);
		parameter.addParamWithType(record.getModifier(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifierId(), Types.VARCHAR);
		parameter.addParamWithType(record.getModifyTime(), Types.VARCHAR);
		parameter.addParamWithType(record.getPubts(), Types.VARCHAR);
		parameter.addParamWithType(record.getTenantId(), Types.VARCHAR);
		parameter.addParamWithType(record.getBarCode(), Types.VARCHAR);
		parameter.addParamWithType(record.getProductTemplate(), Types.VARCHAR);
		parameter.addParamWithType(record.getEnableAssistUnit(), Types.BIT);
		parameter.addParamWithType(record.getIsSerialNoManage(), Types.BIT);
		parameter.addParamWithType(record.getIsBarcodeManage(), Types.BIT);
		parameter.addParamWithType(record.getAllowNegativeInventory(), Types.BIT);
		parameter.addParamWithType(record.getIsBatchManage(), Types.BIT);
		parameter.addParamWithType(record.getIsExpiryDateManage(), Types.BIT);
		parameter.addParamWithType(record.getDaysBeforeValidityReject(), Types.INTEGER);
		parameter.addParamWithType(record.getValidityWarningDays(), Types.INTEGER);
		parameter.addParamWithType(record.getIsExpiryDateCalculationMethod(), Types.INTEGER);
		parameter.addParamWithType(record.getExpireDateUnit(), Types.VARCHAR);
		parameter.addParamWithType(record.getExpireDateNo(), Types.INTEGER);
		parameter.addParamWithType(record.getRemark_dxq(), Types.LONGVARCHAR);
		parameter.addParamWithType(record.getIsRefresh_dxq(), Types.INTEGER);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductMapper.deleteByPrimaryKey
    
    public int deleteByPrimaryKey(Long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "delete from dxqyy_product where `id` = ?\n";
        parameter.addParamWithType(id, Types.BIGINT);

        
        return ymsJdbcApi.update(sql, parameter);
    }

    //com.yonyou.ucf.mdf.app.isvdxq.other.mapper.ProductMapper.selectById
    
    public ProductEntity selectById(long id) {
        SQLParameter parameter = new SQLParameter(true);
        
        String sql = "select * from dxqyy_product where `id`=?;\n";
        parameter.addParam(id);

        ResultSetProcessor processor = new AutoBeanProcessor(new ProductEntity());
        return (ProductEntity) ymsJdbcApi.queryForObject(sql, parameter, processor);
    }

}
